<?php

use Doraemon\model\DesignerAuth;
use Doraemon\tools\Log;
use Doraemon\model\Member;
use Doraemon\model\Designer;
use Doraemon\service\LocalRank\PublicPraiseRank as sPublicPraiseRank;

class UnRegisterHandleAction extends ActionPlugin
{
    public function main()
    {
        // 调试日志
        Log::info('接收用户注销的事件', $this->messageBody);
        $message = $this->messageBody;
        $table = $this->messageBody['table'] ?? '';
        $uid = 0;
        $extend = [];
        if (strstr($table, Member::_TABLE_NAME)) {
            $uid = $this->messageBody['data']['uid'] ?? 0;
            $type = $this->messageBody['type'] ?? '';
            $user_type = $this->messageBody['data']['type'];
            if ($type == 'update') {
                if ($user_type == Member::AUTH_USER_DESIGNER) {
                    //接收设计师注销事件,处理设计师注销的逻辑
                    //hhz_designer表注销
                    Designer::updateDesigner($uid, ["status" => Designer::STATUS_DELETE]);
                    //hhz_designer_auth表注销,设置为取消认证
                    DesignerAuth::updateInfo($uid, [
                        "auth_status" => DesignerAuth::STATUS_AUTH_CANCEL,
                        'house_article_audit_status' => DesignerAuth::STATUS_AUDIT_SUPPLEMENT,
                        'identity_info_audit_status' => DesignerAuth::STATUS_AUDIT_SUPPLEMENT,
                        'is_pay' => DesignerAuth::NOT_PAID,
                    ]);

                    // 处理本地口碑榜,装修公司被B1永久下榜
                    sPublicPraiseRank::offlineRank(
                        $uid,
                        true,
                        Member::AUTH_DECO_COMPANY,
                        [
                            'reason' => '用户注销'
                        ]
                    );

                    Log::info('成功接收到设计师用户注销的事件! 做注销处理:', [
                        "uid" => $uid,
                    ]);
                }
            }
            $extend = compact('uid', 'user_type');
        }

        Log::info('接收到用户注销的事件', compact('uid', 'message') + $extend);
        $this->setSuccess();
    }
}
